package com.ruoyi.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.PaymentDetail;
import com.ruoyi.web.service.IPaymentDetailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 结算账号明细Controller
 * 
 * @author ruoyi
 * @date 2021-04-06
 */
@Controller
@RequestMapping("/pay/detail")
public class PaymentDetailController extends BaseController
{
    private String prefix = "pay/detail";

    @Autowired
    private IPaymentDetailService paymentDetailService;

    @RequiresPermissions("pay:detail:view")
    @GetMapping()
    public String detail()
    {
        return prefix + "/detail";
    }

    /**
     * 查询结算账号明细列表
     */
    @RequiresPermissions("pay:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PaymentDetail paymentDetail) throws Exception
    {
        startPage();
        List<PaymentDetail> list = paymentDetailService.selectPaymentDetailList(paymentDetail);
        return getDataTable(list);
    }

    /**
     * 导出结算账号明细列表
     */
    @RequiresPermissions("pay:detail:export")
    @Log(title = "结算账号明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PaymentDetail paymentDetail) throws Exception
    {
        List<PaymentDetail> list = paymentDetailService.selectPaymentDetailList(paymentDetail);
        ExcelUtil<PaymentDetail> util = new ExcelUtil<PaymentDetail>(PaymentDetail.class);
        return util.exportExcel(list, "detail");
    }

    /**
     * 新增结算账号明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存结算账号明细
     */
    @RequiresPermissions("pay:detail:add")
    @Log(title = "结算账号明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PaymentDetail paymentDetail)
    {
        return toAjax(paymentDetailService.insertPaymentDetail(paymentDetail));
    }

    /**
     * 修改结算账号明细
     */
    @GetMapping("/edit/{sequenceNo}")
    public String edit(@PathVariable("sequenceNo") String sequenceNo, ModelMap mmap)
    {
        PaymentDetail paymentDetail = paymentDetailService.selectPaymentDetailById(sequenceNo);
        mmap.put("paymentDetail", paymentDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存结算账号明细
     */
    @RequiresPermissions("pay:detail:edit")
    @Log(title = "结算账号明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PaymentDetail paymentDetail)
    {
        return toAjax(paymentDetailService.updatePaymentDetail(paymentDetail));
    }

    /**
     * 删除结算账号明细
     */
    @RequiresPermissions("pay:detail:remove")
    @Log(title = "结算账号明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(paymentDetailService.deletePaymentDetailByIds(ids));
    }
}
